package com.fit.service;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.springframework.stereotype.Component;

import com.fit.beans.BorrowBean;
import com.fit.interfaces.BorrowI;
import com.fit.interfaces.User;
@Component
public class BorrowsBean implements BorrowsI {

	private Map<String, BorrowI> borrows;

	public BorrowsBean(Map<String, BorrowI> borrows) {
		
		this.borrows = borrows;
	}

	public BorrowsBean() {
		borrows = new HashMap<String, BorrowI>();
	}
	
	public BorrowI editSingleBorrow(BorrowI borrow){
		
		return borrows.put(borrow.getName(), borrow);
	}
	
	@CommitAfter
	public BorrowI save(BorrowI borrow){
		return borrows.put(borrow.getName(), borrow);
	}
	
	/* (non-Javadoc)
	 * @see com.fit.service.BorrowsI#retrive()
	 */
	public Collection<BorrowI> retrive(){
		return borrows.values();
	}
	
	/* (non-Javadoc)
	 * @see com.fit.service.BorrowsI#retriveSingleBorrow(java.io.Serializable)
	 */
	public BorrowI retriveSingleBorrow(Serializable id){
		return borrows.get(id);
	}

	@Override
	public Collection<BorrowI> retrive(Serializable id) {
		return (Collection<BorrowI>) borrows.get(id);
	}
	
	/* (non-Javadoc)
	 * @see com.fit.service.BorrowsI#retrivesingleBorrow(java.util.Date)
	 */
//	public Collection<BorrowI> retrivesingleBorrow(Date dateOfBorrow){
//		return (Collection<BorrowI>) borrows.get(dateOfBorrow);
//	}
	
}
